var api = require('../../config/api.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    psCustomerCode: '',
    feedbackList: [],
    feedBackState: 1,
    mPageNum: 1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.data.feedBackState = options.feedBackState
    this.doHttpGetFeedbackStatisticsList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    var that = this
    that.setData({
      mPageNum: 1
    })
    that.doHttpGetFeedbackStatisticsList()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    var that = this
    let num = that.data.mPageNum
    that.setData({
      mPageNum: num += 1
    });
    that.doHttpGetFeedbackStatisticsList()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },

  /**
   * 获取我的上报列表
   */
  doHttpGetFeedbackStatisticsList: function () {
    var that = this
    wx.getStorage({
        key: 'psCustomerCode',
        success: (res) => {
            that.setData({
            psCustomerCode: res.data
          });
          console.log('psCustomerCode:', that.data.psCustomerCode)
            wx.request({
            url: api.feedbackFindAllByCondition,
            method: 'POST',
            data: {
                psCustomerCode: that.data.psCustomerCode,
                feedbackType: 3,
                feedbackState: parseInt(that.data.feedBackState),
                feedbackClassification: 2,
                pageNum: that.data.mPageNum,
                pageSize: 5
            },
            success: function (res) {
                if (that.data.mPageNum != 1) {
                that.setData({
                    feedbackList: that.data.feedbackList.concat(res.data.data.rows)
                });
                } else {
                wx.stopPullDownRefresh()
                that.setData({
                    feedbackList: res.data.data.rows
                });
                }
            }
            })
        }
    })
  },

  toFeedBackDetails: function (e) {
    wx.navigateTo({
        url: "/pages/MyReport/ReportDetail/ReportDetail?feedbackCode="+ e.currentTarget.dataset.idtype.feedbackCode
      });
  },
})